#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    //table widget 控件
    //设置列数
    ui->tableWidget->setColumnCount(3);

    //设置水平表头
    ui->tableWidget->setHorizontalHeaderLabels(QStringList()<<"姓名"<<"性别"<<"年龄");

    //设置行数
    ui->tableWidget->setRowCount(5);

    //设置正文
    //ui->tableWidget->setItem(0,0,new QTableWidgetItem("亚瑟"));

    //利用循环设置正文    QString::fromLocal8Bit
    QStringList namelist;
    namelist<<"亚瑟"<<"妲己"<<"an qila"<<"zhao yun"<<"sun wukong";
    QList<QString> sexlist;
    sexlist<<"man"<<"woman"<<"woman"<<"man"<<"null";

    for (int i = 0 ; i < 5 ; i ++)
    {
        int col=0;
        ui->tableWidget->setItem(i,col++,new QTableWidgetItem(namelist[i]));
        ui->tableWidget->setItem(i,col++,new QTableWidgetItem(sexlist.at(i)));
        //int 转 QString
        ui->tableWidget->setItem(i,col++,new QTableWidgetItem(QString::number(18+i)));
    }



}

Widget::~Widget()
{
    delete ui;
}
